package com.idemon.springboot;

import com.idemon.springboot.dao.IUserinfoDAO;
import com.idemon.springboot.dao.UserinfoMapper;
import com.idemon.springboot.db.IDBUtil;
import com.idemon.springboot.po.TempConfig;
import com.idemon.springboot.po.Userinfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class HelloController{
    @Value("${userinfo.title}")
    private String title;
    @Autowired
    private Userinfo userinfo;

    @Autowired
    private TempConfig tempConfig;

    @Autowired
    private IDBUtil dbutil;

    @Autowired
    private IUserinfoDAO userinfoDAO;

    @Autowired(required = false)
    private UserinfoMapper userinfoMapper;

    @RequestMapping(value = "/",produces = "text/plain;charset=utf8")
    String index(){
        return this.title + ": Hello " + userinfo.getName() + ",your age is " + userinfo.getAge();
    }

    @RequestMapping(value = "/config")
    String config(){
        return "UploadFile dir:" + tempConfig.getDir() + ",UploadFile size: " + tempConfig.getSize();
    }

    @RequestMapping(value = "/db")
    String db(){
        return dbutil.init();
    }

    /**
     * JDBCTemplate
     * @return
     */
    @RequestMapping("/getall")
    List<Userinfo> getAll(){
        return  userinfoDAO.getAll();
    }


    @RequestMapping("/getallbymybatis")
    List<Userinfo> getAllByMybatis(){
        return  userinfoMapper.getAll();
    }
}
